package top.gangster.lunan.contractservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import top.gangster.lunan.contractservice.entity.ContractState;
import top.gangster.lunan.contractservice.mapper.ContractStateMapper;
import top.gangster.lunan.contractservice.service.ContractStateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 其中的元组是固定的；在数据库设计完成之后，该表的信息不再进行修改。 服务实现类
 * </p>
 *
 * @author kid
 * @since 2021-11-16
 */
@Service
public class ContractStateServiceImpl extends ServiceImpl<ContractStateMapper, ContractState> implements ContractStateService {

	/**
	 * 根据合同状态名称获取ContractState对象
	 * @param stateName 状态名称
	 * @return 合同状态对象
	 */
	@Override
	public ContractState getStateByName(String stateName) {
		QueryWrapper<ContractState> wrapper = new QueryWrapper<>();
		wrapper.eq("name",stateName);
		return this.getOne(wrapper);
	}

	/**
	 * 根据合同状态名称获取状态id
	 * @param stateName 状态名称
	 * @return 合同状态id
	 */
	@Override
	public Integer getStateIdByName(String stateName) {
		ContractState state = this.getStateByName(stateName);
		if (state == null) {
			return null;
		}
		return state.getId();
	}

	/**
	 * 根据合同状态名称模糊查询，获取状态id
	 * @param stateName 模糊状态名称
	 * @return 合同状态对象
	 */
	@Override
	public ContractState getStateByLikeName(String stateName) {
		QueryWrapper<ContractState> wrapper = new QueryWrapper<>();
		wrapper.like("name",stateName);
		return this.getOne(wrapper);
	}

	/**
	 * 根据合同状态名称模糊查询，获取状态id
	 * @param stateName 模糊状态名称
	 * @return 合同状态id
	 */
	@Override
	public Integer getStateIdByLikeName(String stateName) {
		ContractState state = this.getStateByLikeName(stateName);
		if (state == null) {
			return null;
		}
		return state.getId();
	}
}
